<?php
	require_once("php/function.php");
	conn();
	mysql_query("SET NAMES 'utf8'");
	if(isset($_GET['sort']))
	{$sort=$_GET['sort'];}
	if(!isset($_GET['page']))
	{$page=1;}
	else
	{$page=$_GET['page'];}
	$countpage=15;
	if(!empty($_GET['start']) && !empty($_GET['end']))
	{
		require_once("php/jiage.php");
		$r1 = trim($_GET['start']);$r2 = trim($_GET['end']);
		$r1=filtration($r1);$r2=filtration($r2);
		if($tra = statosta($r1,$r2))
		{
			$tra=statosta($r1,$r2);
			$sign = statosta_sign($tra,$r1,$r2);
		}
			
	}
	if(!empty($_GET['train']))
	{
		$r3=trim($_GET['train']);
		$r3=strtoupper($r3);
		$r3=filtration($r3);
		if($tra = tra_num($r3))
		{
			$tra = tra_num($r3);
			$sign=other_sign($tra,$r3);
		}
		
	}
	if(!empty($_GET['station']))
	{
		$r4=$_GET['station'];
		$r4=filtration($r4);
		if($tra = station(trim($r4)))
		{
				$tra=station(trim($r4));
				$sign=other_sign($tra,$r4);
		}
		
	}
	$t = count(@$tra);/*获取车次趟数*/
	if(!empty($sign))
	{
		for($i=0;$i< $t;$i++)
		{
			$start[$i]=$sign[$i][3];
			$run[$i]=$sign[$i][2];
		}
	}
	if(isset($sort))
	{
		$data=my_sort($tra,$start,$run,$sign,$sort);
		$tra=$data[0];
		$sign=$data[1];
	}
	$pagemin=($page-1)*$countpage;
	$pagemax=$page*$countpage-1;
	$pagenum=intval($t/$countpage+1);
	if($t%$countpage==0)
	{$pagenum--;}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href= "style/style.css " rel= "stylesheet" type= "text/css">
<!--[if lt IE 8]> <link rel="stylesheet" type="text/css" href="style/ie.css" /> <![endif]--> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="到会,列车,列车时刻,火车,查询,火车查询,车次查询" /> 
<title>列车时刻查询-到会网</title>
<script type="text/javascript"  src="js/js.js" ></script>
<script type="text/javascript" src="js/jquery-1.2.1.pack.js"></script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20046272-1']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>
<center>
<div id="main" >
	<div id="logo">
			
	</div>
	<script type="text/javascript">
google_ad_client = "ca-pub-4388693486177547";
/* lccx */
google_ad_slot = "5317663943";
google_ad_width = 728;
google_ad_height = 90;

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
	<div id="head">
		<div id="head_massege">
			<?php 
			if(isset($tra) && empty($tra))
			{
				echo "<br /><br /><br /><br />";
				echo "<span>没有查询结果</span>";
			}
			else
			{
				if(isset($r1))
				{
					echo "<br /><br />";
					echo "<span>从".$r1."到".$r2."</span>";
					echo "<br /><br />";
					echo "共<span style='color:red;'>".$t."</span>次列车经过";
				}
				if(isset($r3))
				{
					echo "<br /><br />";
					echo "<span>".$r3."</span>";
					echo "<br /><br />";
					echo "<span style='color:red;'>".$tra[0][0][13]."</span> ";
					echo "<br /><br />";
					echo "共<span style='color:red;'>".count($tra[0])."</span>个站点";
				}
				if(isset($r4) && isset($t))
				{
					echo "<br /><br />";
					echo "<span>".$r4."</span>";
					echo "<br /><br />";
					echo "共<span style='color:red;'>".$t."</span>趟车次经过";
				}
			}
			?>
		</div>
		<div id="head_search">
			<div id="box">
				<br />
				<form method="GET" action="index.php">
					<div id="s_box3" style="display:inline;">
					  从<input  size="25" type="text" name="start"  value="<?php echo stripslashes(@$r1); ?>" id="inputString1" onkeyup="lookup(this.value,1);" onblur="fill(1);" autocomplete="off" />			
						<div class="suggestionsBox" id="suggestions1" style="display: none;">
							<img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
							<div class="suggestionList" id="autoSuggestionsList1">
							</div>
						</div>
						到<input size="25" name="end"  value="<?php echo stripslashes(@$r2); ?>" type="text"   id="inputString2" onkeyup="lookup(this.value,2);" onblur="fill(2);"  autocomplete="off"/>
						<div class="suggestionsBox" id="suggestions2" style="display: none;">
						<img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
						<div class="suggestionList" id="autoSuggestionsList2"></div></div>
					<input type="submit"  class="searchbtn3" onmouseover="this.className='searchbtn2'" onmouseout="this.className='searchbtn3'" value="" />
					</div>
				</form>
				<form method="GET" action="index.php">
					<div id="s_box2" style="display: none;">				
						<input size="25" name="train" value="<?php echo stripslashes(@$r3); ?>" type="text"class="input_txt2" id="inputString4" onkeyup="lookup(this.value,4);" onblur="fill(4);" autocomplete="off"/>
						<div class="suggestionsBox" id="suggestions4" style="display: none;">
						<img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
						<div class="suggestionList" id="autoSuggestionsList4"></div></div>
						<input type="submit"  class="searchbtn3" onmouseover="this.className='searchbtn2'" onmouseout="this.className='searchbtn3'" value="" />
					</div>
				</form>
				<form method="GET" action="index.php">
					<div id="s_box1" style="display: none;">
						<input size="25" name="station"  value="<?php echo stripslashes(@$r4); ?>" type="text" class="input_txt2" id="inputString3" onkeyup="lookup(this.value,3);" onblur="fill(3);" autocomplete="off"/>
						<div class="suggestionsBox" id="suggestions3" style="display: none;">
						<img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
						<div class="suggestionList" id="autoSuggestionsList3"></div></div>
						<input type="submit"  class="searchbtn3" onmouseover="this.className='searchbtn2'" onmouseout="this.className='searchbtn3'" value="" />
					</div>
				</form>
			</div>
				<br />
			<div>
				<input type="radio"  name="SearchType" value="statosta" onclick="statosta()" checked=true />站站查询 &nbsp;&nbsp;
				<input type="radio"  name="SearchType" value="train"  onclick="train()" />车次查询 &nbsp;&nbsp;
				<input type="radio"  name="SearchType" value="station" onclick="station()" />站点查询 &nbsp;&nbsp;
				<?php
				if(isset($r1))
				{
					echo '<script>window.load=statosta1();</script>';
				}
				elseif(isset($r3))
				{
					echo '<script>window.load=train1();</script>';
				}
				elseif(isset($r4))
				{
					echo '<script>window.load=station1();</script>';
				}
				else{}
				?>
			</div>
		</div>
  </div>
	<?php 
		if(!empty($tra))
		{
	?>
	<div id="center">
		<table>
			<tr style="background:rgb(245,248,255);">
				<td width="135px">车次</td>
					<td style="width:110px">车型</td>
					<td style="width:180px">发站-到站</td>
					<td style="width:105px">发时-到时<?php if(!isset($r3) and !empty($tra)){?><a href="<?php if(isset($sort) and $sort==2){$url_sort=-2;}else {$url_sort=2;} echo hrefsort($url_sort); ?>"><?php if(!isset($sort) or $sort==2 or $sort==3 or $sort==-3){echo '<img src="images/paixu.gif">';}else {echo '<img src="images/paixu2.gif">';}?></a><?php }?></td>
					<td style="width:140px">运行时间<?php if(!isset($r3) and !empty($tra)){?><a href="<?php if(isset($sort) and $sort==3){$url_sort=-3;}else {$url_sort=3;} echo hrefsort($url_sort); ?>"><?php if(!isset($sort) or $sort==3 or $sort==2 or $sort==-2){echo '<img src="images/paixu.gif">';}else {echo '<img src="images/paixu2.gif">';}?></a><?php }?></td>
					<td style="width:290px">参考票价</td>
			</tr>
			<?php
				for($i=$pagemin;$i< $pagemax && $i< $t;$i++)
				{
					$m = count($tra[$i])/*获取站点数目*/;
					if(!strcmp($tra[$i][0][13],"动车组") or !strcmp($tra[$i][0][13],"城际高速")or !strcmp($tra[$i][0][13],"高速动车"))
					{$flag=1;}
					else
					{$flag=2;}
			?>
			<tr onmouseover="this.className='on'" onmouseout="this.className='off1'">
				<td><a href="#" onclick="hid(<?php echo $i.','.$t.','.$pagemax.','.$pagemin; ?>);return false;"  ><?php echo $tra[$i][0][0];?></a></td>
					<td><?php echo $tra[$i][0][13];?></td>
					<td>
							<?php
							  $i1 = $i;$i2 = $i;
							  $j1 = $sign[$i][0];$j2 = $sign[$i][1];
							  $time=$sign[$i][2];
								echo $tra[$i1][$j1][1]."--".$tra[$i2][$j2][1];
								if(isset($i1) && isset($i2)){
							?>
					</td>
					<td>
						<?php 
								echo date("H:i",@$tra[$i1][$j1][4])."--".date("H:i",@$tra[$i2][$j2][3]);
						?>
					</td>
					<td>
						<?php 
							if(intval($time/60)=="0")
							{echo ($time%60).'分钟';}
							else
							{echo intval($time/60).'小时'.($time%60).'分钟';} 
						?>
					</td>
					<td>
						<?php
							if(!empty($r1))
							{
								if($j1!=0)
								{
									$money = jiage($tra[$i],$sign[$i]);
									if($flag=="2")
									{
										echo "<span style='font-size:12px;'>";
										if($tra[$i][$j2][8]!="--")
										{echo "硬座".$money[0];}
										if($tra[$i][$j2][9]!="--")
										{echo " 软座".$money[1];}
										if($tra[$i][$j2][10]!="--")
										{echo " 硬卧".$money[2]."/".$money[3]."/".$money[4];}
										if($tra[$i][$j2][11]!="--")
										{echo " 软卧".$money[5]."/".$money[6];}
										echo "</span>";
									}
									else
									{
										echo "<span style='font-size:12px;'>";
										echo "暂无计算公式";
										echo "</span>";
									}
								}
								else
								{
									echo "<span style='font-size:12px;'>";
									if($tra[$i][$j2][8]!="--")
										{echo "硬座".$tra[$i][$j2][8];}
									if($tra[$i][$j2][9]!="--")
										{echo " 软座".$tra[$i][$j2][9];}
									if($tra[$i][$j2][10]!="--")
										{echo " 硬卧".$tra[$i][$j2][10];}
									if($tra[$i][$j2][11]!="--")
										{echo " 软卧".$tra[$i][$j2][11];}
									echo "</span>";	
								}
							}
							else
							{
								echo "<span style='font-size:12px;'>";
								if($tra[$i][$j2][8]!="--")
									{echo "硬座".$tra[$i][$m-1][8];}
								if($tra[$i][$j2][9]!="--")
									{echo " 软座".$tra[$i][$m-1][9];}
								if($tra[$i][$j2][10]!="--")
									{echo " 硬卧".$tra[$i][$m-1][10];}
								if($tra[$i][$j2][11]!="--")
									{echo " 软卧".$tra[$i][$m-1][11];}
								echo "</span>";
							}
						?>
					</td>
			</tr>
			<tr id="train<?php echo $i;?>" style="display:none;">
			<?php
				if(isset($r3))
				{echo "<script>window.load=xstrain();</script>";}
			?>
				<td align="center" colspan="6" >
					<div id="content">
						<table>
							<table>
								<tr style="background:rgb(186,224,216);text-align:center;">
									<td width="45">站次</td>
									<td width="85">站名</td>
									<td width="75">到达日</td>
									<td width="70">到站时间</td>
									<td width="70">发车时间</td>
									<td width="80">停留时间</td>
									<td width="115">运行时间</td>
									<td width="65">里程</td>
									<?php
										if($flag=="1")
										{ 
									?>
									<td width="60">一等座</td>
									<td width="60">二等座</td>
									<?php }else{?>
									<td width="60">硬座</td>
									<td width="60">软座</td>
									<?php } ?>
									<td width="110">硬卧上/中/下</td>
									<td width="100">软卧上/下</td></tr>
								</tr>
								<?php 
									for($j=0;$j<$m;$j++)
									{
								?>
								<tr class="<?php 
															if($j>=$j1 && $j<=$j2)
															{echo "bj";} 
															
														?>" 
										onmouseover="this.className='on'" 
										onmouseout="this.className='<?php if($j>=$j1 && $j<=$j2){echo "bj";} 
																											else{echo "off2";} ?>'">
									<td style="text-align:center;"><?php echo $j+1; ?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][1];?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][2];?></td>
									<td style="text-align:center;">
											<?php 
												if($tra[$i][$j][3]!="0")
												{
													echo date("H:i",$tra[$i][$j][3]);
												}
												else
												{echo "--";}
											?>
									</td>
									<td style="text-align:center;">
											<?php 
												if($tra[$i][$j][4]!="0")
												{
													echo date("H:i",$tra[$i][$j][4]);
												}
												else
												{echo "--";}
											?>
									</td>
									<td style="text-align:center;">
											<?php
												if($tra[$i][$j][5]>0 && $tra[$i][$j][5]<50)
											 	{echo $tra[$i][$j][5]."分钟";}
											 	else
											 	{echo "--";}
											?>
									</td>
									<td style="text-align:center;">
											<?php
												if($j!=0)
												{
													$len = strlen($tra[$i][$j][6]);
													for($z=0;$z<$len;$z++)
													{
														if($tra[$i][$j][6][$z]==":")
														{echo "小时";}
														else
														{echo $tra[$i][$j][6][$z];}
													}
													echo "分钟";
												} 
												else{echo "--";}
											?>
									</td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][7]."km";?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][8];?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][9];?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][10];?></td>
									<td style="text-align:center;"><?php echo $tra[$i][$j][11];?></td>
								</tr>
									<?php } ?>
						</table>
					</div>
				</td>
			</tr>
				<?php }}?>
		</table>
	</div>
	<div id="foot">
		<?php 
		if(isset($pagenum) and $pagenum!=1 and $page<=$pagenum)
	    {
			echo "<span style='color:blue;'>".$page."/".$pagenum."</span>";
			echo "&nbsp;&nbsp;&nbsp;&nbsp;";
			if($page!=1)
			{
				echo '<a href="'.hrefpage(1).'">首页</a>';
			}
			echo "&nbsp;&nbsp;&nbsp;&nbsp;";
			if($page-1>0)
			{
				echo '<a href="'.hrefpage($page-1).'">上一页</a>';
			}
			for($i=$page-3;$i<=$page+3 && $i<=$pagenum;$i++)
			{
				if($i>0)
				if($i==$page)
				{
					echo '<a href="'.hrefpage($i).'"><b><span style="color:red;">'.$i.'</span></b> </a>';
				}
				else
				{
					echo '<a href="'.hrefpage($i).'">'.$i.' </a>';
				}
			}
			if(($page+1) <= $pagenum)
			{
			echo '<a href="'.hrefpage($page+1).'">下一页</a>';
			}
		}
	}
	?>
	<br />
	<br />
		<p>
			Copyright &copy; 2010  版权所有者：张意乾、罗红胜、何璇
			<script src="http://s16.cnzz.com/stat.php?id=2628833&web_id=2628833&show=pic1" language="JavaScript"></script>
			<script src="http://s16.cnzz.com/stat.php?id=2629594&web_id=2629594" language="JavaScript"></script>
		</p>
		
		<script type="text/javascript">
			google_ad_client = "ca-pub-4388693486177547";
				/* lcskcx */
			google_ad_slot = "5854996030";
			google_ad_width = 728;
			google_ad_height = 15;
		</script>
		<script type="text/javascript"
				src=" http://pagead2.googlesyndication.com/pagead/show_ads.js">
		</script>
	</div>
</div>
</body>
</center>
</html>